# -*- coding: utf-8 -*-
from pprint import pprint
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
from sklearn import metrics

def plot_roc_from_npy(data_lst, model_name_lst):
    plt.figure(1)
    plt.plot([0, 1], [0, 1], 'k--')
    ax = plt.gca()
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1.01)

    for d_i, d in enumerate(data_lst):
        roc_auc = metrics.auc(d[0], d[1])
        display = metrics.RocCurveDisplay(fpr=d[0], tpr=d[1], roc_auc=roc_auc, name=model_name_lst[d_i])
        display.plot(ax=ax)
    plt.show()
    print('Done!')

if __name__ == '__main__':

    base_p = Path(r'C:\MyNuts\kerasStudy\paper01_new\results(fprTpr)\20221104')
    # 非平衡策略下， weights 1 to 1
    lr_fpr_tpr=np.load(base_p/'fprTpr_weights_1to1_wlr_test.npy')
    rf_fpr_tpr=np.load(base_p/'fprTpr_weights_1to1_wrf_test.npy')
    dfcnn_fpr_tpr = np.load(base_p/'fprTpr_weights_1to1_dnn_test.npy')
    lstm_fpr_tpr = np.load(base_p/'fprTpr_weights_1to1_lstm_test.npy')
    data_lst = [lr_fpr_tpr, rf_fpr_tpr, dfcnn_fpr_tpr,lstm_fpr_tpr]
    name_lst = ['LR', 'RF', 'DFCNN', 'LSTM']
    plot_roc_from_npy(data_lst, name_lst)


    # 平衡策略下， weights 1 to 4
    wlr_fpr_tpr=np.load(base_p/'fprTpr_weights_1to4_wlr_test.npy' )
    wrf_fpr_tpr=np.load(base_p/'fprTpr_weights_1to4_wrf_test.npy')
    wdfcnn_fpr_tpr = np.load(base_p/'fprTpr_weights_1to4_dnn_test.npy' )
    wlstm_fpr_tpr = np.load(base_p/'fprTpr_weights_1to4_lstm_test.npy' )
    wdata_lst = [wlr_fpr_tpr, wrf_fpr_tpr, wdfcnn_fpr_tpr, wlstm_fpr_tpr]
    wname_lst = ['LR', 'RF', 'DFCNN', 'LSTM']
    plot_roc_from_npy(wdata_lst, wname_lst)


